package com.ymatou.iapi.sellerquery.testcase;

import java.util.ArrayList;
import java.util.HashMap;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellerquery.parameter.GetOrderHistoryBean;
import com.ymatou.iapi.sellerquery.parameter.resp.CreditInfoListResp;
import com.ymatou.iapi.sellerquery.parameter.resp.OrderHistoryListResp;
import com.ymatou.iapi.sellerquery.service.GetOrderHistoryCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.sqlwapper.DefaultWapper;
import com.ymttest.utils.DataUtil;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.constant.ECode;

/**
 * 获取订单历史 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetOrderHistory {

	private static GetOrderHistoryBean getorderhistorybean;
	private static GetOrderHistoryCall getorderhistorycall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取订单历史");
	}

	@Before
	public void caseUp() {

		getorderhistorybean = new GetOrderHistoryBean();
		getorderhistorycall = new GetOrderHistoryCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getorderhistorycall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderHistory_001() {
		Logger.start(true,"获取订单历史成功");
		try {			
			// 参数
			getorderhistorybean.setOrderId(112451223);
			getorderhistorybean.setUserId(20226821);
			String s=FormatUtil.beanToHttpString(getorderhistorybean, true, false);
			// 发送请求
			getorderhistorycall.setData(s);
			getorderhistorycall.callService();
			Logger.comment("getorderhistorycall send:" + getorderhistorycall.getEntityString());
			Logger.comment("getorderhistorycall response:" + getorderhistorycall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, getorderhistorycall.getCode(), "验证Code");
			int OrderId = 112451223;
			//数据库验证			
			DefaultWapper database = new DefaultWapper();
			ArrayList<OrderHistoryListResp> list = getorderhistorycall.getResult();	
			int i = 0;
            for (OrderHistoryListResp orderHistoryList : list) {			
            	DataUtil.verifyDateEquals(database.selectTradingStatusByOrderId(OrderId).get(i).get("dUpdateTime"),
            			orderHistoryList.getUpdateTime(),"验证交易状态记录表dUpdateTime");
            	Logger.verifyEquals( database.selectTradingStatusByOrderId(OrderId).get(i).get("mMemo"), 
						orderHistoryList.getMemo(), "验证交易状态记录表mMemo");
            	Logger.verifyEquals( database.selectTradingStatusByOrderId(OrderId).get(i).get("iTraddingId"), 
						orderHistoryList.getTraddingId(), "验证交易状态记录表iTraddingId");
            	Logger.verifyEquals( database.selectTradingStatusByOrderId(OrderId).get(i).get("sTradingStatusId"), 
						orderHistoryList.getTradingStatusId(), "验证交易状态记录表iTradingStatusId");
            	Logger.verifyEquals( database.selectTradingStatusByOrderId(OrderId).get(i).get("iTradingStatus"), 
						orderHistoryList.getTradingStatus(), "验证交易状态记录表iTradingStatus");
            	i++;
			}
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetOrderHistory_002() {
		Logger.start(false,"订单号为空，获取订单历史失败");
		try {
			
			// 参数
		    //getorderhistorybean.setOrderId(112451223);
			getorderhistorybean.setUserId(20226821);
			String s=FormatUtil.beanToHttpString(getorderhistorybean, true, false);
			// 发送请求
			getorderhistorycall.setData(s);
			getorderhistorycall.callService();
			Logger.comment("getorderhistorycall send:" + getorderhistorycall.getEntityString());
			Logger.comment("getorderhistorycall response:" + getorderhistorycall.getReturnData());
			Logger.verifyEquals(ECode.FAILED400, getorderhistorycall.getCode(), "验证Code");
			Logger.verifyEquals(ECode.BCODE8, getorderhistorycall.getBCode(), "验证BCode");
			Logger.verifyEquals("orderId:订单号不能为0", getorderhistorycall.getMsg(), "验证Msg");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderHistory_003() {
		Logger.start(true,"订单号不存在，获取订单历史为空，成功");
		try {
			
			// 参数
		    getorderhistorybean.setOrderId(123456789);
			getorderhistorybean.setUserId(20226821);
			String s=FormatUtil.beanToHttpString(getorderhistorybean, true, false);
			// 发送请求
			getorderhistorycall.setData(s);
			getorderhistorycall.callService();
			Logger.comment("getorderhistorycall send:" + getorderhistorycall.getEntityString());
			Logger.comment("getorderhistorycall response:" + getorderhistorycall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, getorderhistorycall.getCode(), "验证Code");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_GetOrderHistory_004() {
		Logger.start(false,"买家Id为空，获取订单历史失败");
		try {
			
			// 参数
		    getorderhistorybean.setOrderId(112451223);
		    //getorderhistorybean.setUserId(20226821);
			String s=FormatUtil.beanToHttpString(getorderhistorybean, true, false);
			// 发送请求
			getorderhistorycall.setData(s);
			getorderhistorycall.callService();
			Logger.comment("getorderhistorycall send:" + getorderhistorycall.getEntityString());
			Logger.comment("getorderhistorycall response:" + getorderhistorycall.getReturnData());
			Logger.verifyEquals(ECode.FAILED400, getorderhistorycall.getCode(), "验证Code");
			Logger.verifyEquals(ECode.BCODE8, getorderhistorycall.getBCode(), "验证BCode");
			Logger.verifyEquals("userId:用户号不能为0", getorderhistorycall.getMsg(), "验证Msg");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderHistory_005() {
		Logger.start(true,"买家Id不存在，获取订单历史为空，成功");
		try {
			
			// 参数
		    getorderhistorybean.setOrderId(112451223);
			getorderhistorybean.setUserId(123456789);
			String s=FormatUtil.beanToHttpString(getorderhistorybean, true, false);
			// 发送请求
			getorderhistorycall.setData(s);
			getorderhistorycall.callService();
			Logger.comment("getorderhistorycall send:" + getorderhistorycall.getEntityString());
			Logger.comment("getorderhistorycall response:" + getorderhistorycall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, getorderhistorycall.getCode(), "验证Code");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderHistory_006() {
		Logger.start(true,"买家Id不存在和订单号均为空，获取订单历史失败");
		try {
			
			// 参数
		    //getorderhistorybean.setOrderId(112451223);
			//getorderhistorybean.setUserId(123456789);
			String s=FormatUtil.beanToHttpString(getorderhistorybean, true, false);
			// 发送请求
			getorderhistorycall.setData(s);
			getorderhistorycall.callService();
			Logger.comment("getorderhistorycall send:" + getorderhistorycall.getEntityString());
			Logger.comment("getorderhistorycall response:" + getorderhistorycall.getReturnData());
			Logger.verifyEquals(ECode.FAILED400, getorderhistorycall.getCode(), "验证Code");
			Logger.verifyEquals(ECode.BCODE8, getorderhistorycall.getBCode(), "验证BCode");
			Logger.verifyEquals("userId:用户号不能为0|orderId:订单号不能为0", getorderhistorycall.getMsg(), "验证Msg");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetOrderHistory_007() {
		Logger.start(true,"买家Id不存在和订单号均不存在，获取订单历史为空，成功");
		try {
			
			// 参数
		    getorderhistorybean.setOrderId(1111111);
			getorderhistorybean.setUserId(1111111);
			String s=FormatUtil.beanToHttpString(getorderhistorybean, true, false);
			// 发送请求
			getorderhistorycall.setData(s);
			getorderhistorycall.callService();
			Logger.comment("getorderhistorycall send:" + getorderhistorycall.getEntityString());
			Logger.comment("getorderhistorycall response:" + getorderhistorycall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, getorderhistorycall.getCode(), "验证Code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}